<template>
  <div class="page">
    <back-btn></back-btn>
    <div class="page-wrap">
      <div class="head">
        <div class="tab_bubble">
          <span class="bubble"></span>
          <div class="title">职业列表</div>
        </div>
        <search @search="search"></search>
      </div>
      <div class='card' v-if="categoryList.length>0">
        <a class="maoHref" :href="'#'+item.id" :class="index===currentIndex?' activeCategory ':''" v-for='(item,index) in categoryList' :key='index' @click='categoryClick(index)'>{{item.name}}</a>
      </div>
      <no-content v-else :text="text"></no-content>
      <div class="list-wrap scroll-wrap" id="listWrap">
        <div class='major-item' :id="item.id" v-for="(item,index) in majorData" :key="index">
          <div class='item-category' :title="item.name">{{item.name}}</div>
          <ul class="major">
            <li v-for="(mItem,mIndex) in item.careers" :key="mIndex">
              <nuxt-link :to="'profession-detail?id='+mItem.id" :title="mItem.name">{{mItem.name}}</nuxt-link>
            </li>
            <div class="clear"></div>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { api } from '@/utils'
import majorList from '~/components/majorList'
export default {
  layout: 'zhiyuan',
  data () {
    return {
      categoryList: [],
      majorData: [],
      currentIndex: 0,
      text: '正在加载数据...'
    }
  },
  components: {
    majorList
  },
  methods: {
    // 清除锚链接
    removeMaoHref (obj) {
      location.replace(obj.href)
      return false
    },
    categoryClick (index) {
      this.currentIndex = index
      let maoHref = document.querySelectorAll('.maoHref')
      this.removeMaoHref(maoHref[index])
    },
    search (e) {
      if (e.trim() !== '') {
        this.$store.commit('SET_SEARCH_VAL', e)
        this.$router.push(`search?fromWhere=${2}`)
      }
    }
  },
  beforeMount () {
    this.$axios.get(api.zhiyuanGetCareersTree).then(data => {
      if (data.length > 0) {
        this.text = ''
        this.lodash.map(data, (item) => {
          this.categoryList.push({
            id: item.id,
            name: item.name
          })
        })
        this.majorData = data
      } else {
        this.text = '暂无数据'
      }
    })
  }
}
</script>
<style lang="scss" scoped>
.page {
  height: 100%;
  .head {
    width: 100%;
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    /deep/ .search {
      padding: 0;
      margin: 0;
      line-height: 30px;
      text-align: right;
      width: 51%;
      display: flex;
      justify-content: flex-end;
      >div{
        margin: 0;
      }
      input[type="text"] {
        padding-left: 30px;
        width: 90%;
      }
    }
  }
}
.page-wrap {
  padding: 0 24px;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.tab-bar {
  position: relative;
  span {
    color: $stable02;
    font-size: 24px;
    cursor: pointer;
    &:not(:last-child) {
      margin-right: 30px;
    }
  }
  span.active {
    color: $dark01;
    position: relative;
  }
  .triped {
    height: 6px;
    width: 32px;
    position: absolute;
    left: 0;
    background: $energized;
    transition: all ease 0.35s;
  }
}
.card {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  &:before {
    content: "";
    position: absolute;
    left: 0;
    bottom: -10px;
    width: 100%;
    border-bottom: 1px solid $stable-ec;
  }
  a {
    font-size: 18px;
    margin: 0 23px 23px 0;
    padding: 2px;
    color: $dark;
    cursor: pointer;
    display: inline-block;
  }
  .activeCategory {
    color: $light;
    background-color: $positive;
    transition: all ease 0.35s;
  }
}
.list-wrap {
  flex: 1;
  // overflow-y: auto;
  margin-top: 30px;
  /* display: flex;
  flex-direction: column;
  height: 100%; */
}
.major-item {
  margin-top: -40px;
  padding-top: 60px;
  .item-category {
    color: $positive;
    font-size: 24px;
    margin-bottom: 15px;
  }
  .major {
    color: $dark;
    font-size: 14px;
    li {
      float: left;
      line-height: 30px;
      text-align: left;
      max-width: 180px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      &:not(:last-child) {
        margin-right: 50px;
      }
      > a:hover {
        color: $positive;
      }
    }
    .clear {
      clear: both;
    }
  }
}
</style>
